import pygame, sys, random
pygame.init()
pygame.key.set_repeat(100, 25)

screen = pygame.display.set_mode([800,600])
screen.fill([147,180,109])
print "welcome you Ding Bag!!!!!!!!!!!!!!!!!!!!!!!!!!!"
print "I hate you?????"

class Player:
    def __init__(self, speed):
        self.rect = pygame.Rect(200,300,11,29)
        self.speed = speed
        self.points = 0 
        self.color = [211,123,200]

    def paint(self, screen):
        pygame.draw.rect(screen, self.color, self.rect, 0)
        
    def move(self, screen, direction):
        if direction == "up":
            self.rect.top -= self.speed
            if self.rect.top < 0:
                self.rect.top = 0
        elif direction == "down":
            self.rect.top += self.speed
            if self.rect.bottom > screen.get_height():
                self.rect.bottom = screen.get_height()            
        elif direction == "left":
            self.rect.left -= self.speed
            if self.rect.left < 0:
                self.rect.left = 0
        elif direction == "right":
            self.rect.left += self.speed
            if self.rect.right > screen.get_width():
                self.rect.right = screen.get_width()                


class EnemyVictim:
    def __init__(self, maximumSpeed, randomFrequency, pointsOnImpact):
        self.maximumSpeed = maximumSpeed
        self.randomFrequency = randomFrequency
        self.horizontalSpeed = random.randint(-1*(maximumSpeed-1), maximumSpeed)
        self.verticalSpeed = random.randint(-1*(maximumSpeed-1), maximumSpeed)
        self.rect = pygame.Rect(100,200,20,22)
        self.color = [100,50,25]
        self.pointsOnImpact = pointsOnImpact
        self.justHit = False
        
    def paint (self, screen):
        pygame.draw.rect(screen, self.color, self.rect, 0)
        
    def move(self, screen):
        if self.rect.right > screen.get_width():
            self.rect.right = screen.get_width()
            self.horizontalSpeed = self.horizontalSpeed * -1 
        elif self.rect.left < 0:
            self.rect.left = 0
            self.horizontalSpeed = self.horizontalSpeed * -1 
        elif self.rect.bottom > screen.get_height():
            self.rect.bottom = screen.get_height()
            self.verticalSpeed = self.verticalSpeed * -1 
        elif self.rect.top < 0: 
            self.rect.top = 0
            self.verticalSpeed = self.verticalSpeed * -1
        elif random.randint(0, self.randomFrequency) == 1:
            self.horizontalSpeed = random.randint(-1*(self.maximumSpeed-1), self.maximumSpeed)
            self.verticalSpeed = random.randint(-1*(self.maximumSpeed-1), self.maximumSpeed)
            
        self.rect.left += self.horizontalSpeed
        self.rect.top += self.verticalSpeed


class PoliceEnemy:
    def __init__(self, speed, playerToChase, pointsOnImpact):
        self.maximumSpeed = speed
        self.horizontalSpeed = 0
        self.verticalSpeed = 0
        self.playerToChase = playerToChase
        self.rect = pygame.Rect(100,200,40,44)
        self.color = [0,0,0]
        self.pointsOnImpact = pointsOnImpact
        self.justHit = False
        self.moveFrequency = 3
        self.frameCount = 0
        
        
    def paint (self, screen):
        pygame.draw.rect(screen, self.color, self.rect, 0)
        
    def move(self, screen):
        if (self.frameCount < self.moveFrequency):
            self.frameCount += 1
            return
        else:
            self.frameCount = 0
            
        
        if self.rect.right > screen.get_width():
            self.rect.right = screen.get_width()
            self.horizontalSpeed = self.horizontalSpeed * -1 
        elif self.rect.left < 0:
            self.rect.left = 0
            self.horizontalSpeed = self.horizontalSpeed * -1 
        elif self.rect.bottom > screen.get_height():
            self.rect.bottom = screen.get_height()
            self.verticalSpeed = self.verticalSpeed * -1 
        elif self.rect.top < 0: 
            self.rect.top = 0
            self.verticalSpeed = self.verticalSpeed * -1
        else:
            xDifference = self.playerToChase.rect.left - self.rect.left
            yDifference = self.playerToChase.rect.top - self.rect.top
            multiplier = 1
            if abs(yDifference) > abs(xDifference):
                if (yDifference < 0): multiplier *= -1
                self.verticalSpeed = self.maximumSpeed * multiplier
                if (yDifference == 0): self.horizontalSpeed = 0
                else: self.horizontalSpeed = (self.maximumSpeed * xDifference) / yDifference
            else:
                if (xDifference < 0): multiplier *= -1
                self.horizontalSpeed = self.maximumSpeed * multiplier
                if (xDifference == 0): self.verticalSpeed = 0
                else: self.verticalSpeed = (self.maximumSpeed * yDifference) / xDifference
            
            
        self.rect.left += self.horizontalSpeed
        self.rect.top += self.verticalSpeed

        
    

player1 = Player(7)
enemy1 = EnemyVictim(7, 50, 5)

enemy2 = EnemyVictim(9, 200, 1)
enemy2.color = [255,0,255]

enemy3 = EnemyVictim(11, 20, 5)
enemy3.color = [0,255,255]

enemy4 = EnemyVictim(15, 10, 20)
enemy4.color = [255,255,0]

police1 = PoliceEnemy(2, player1, -25)
police1.color = [255,255,255]

enemyList = [enemy1, enemy2, enemy3, enemy4, police1]

font = pygame.font.Font(None, 60)
score_text = font.render(str(player1.points), 1, (20, 30, 10))
textpos = [10, 11]

def paintGame():
    global player1, enemyList, screen
    screen.fill([147,180,109])
    player1.paint(screen)
    
    for enemy in enemyList:
        enemy.paint(screen)
    
    screen.blit(score_text, textpos)
    pygame.display.flip()

    
gameIsRunning = True
while gameIsRunning:
    print "I'm in need of a new  CPU,memory sticks,power supply,and a new cooling fan!!!!$"
    for enemy in enemyList:
        enemy.move(screen)
    
    for event in  pygame.event.get():
        if event.type == pygame.QUIT:
           gameIsRunning = False
            
        elif event.type == pygame.KEYDOWN:
            
            if event.key == pygame.K_UP:
                player1.move(screen, "up")            
            elif event.key == pygame.K_DOWN:
                player1.move(screen, "down")          
            elif event.key == pygame.K_RIGHT:
                player1.move(screen, "right")            
            elif event.key == pygame.K_LEFT:
                player1.move(screen, "left")
        
                
    for enemy in enemyList:        
        if player1.rect.colliderect(enemy.rect):
            if enemy.justHit == False: 
                player1.points += enemy.pointsOnImpact
                enemy.justHit = True
        else:
            enemy.justHit = False
            print "I hate fat mice and water."
    score_text = font.render(str(player1.points), 1, (20, 30, 10))                
    
    paintGame()
    pygame.time.delay(20)
    
pygame.quit()
            